package interview;

import java.util.LinkedList;

public class interview_03_06 {
    class AnimalShelf {

        private LinkedList<Integer> cat;
        private LinkedList<Integer> dog;
        public AnimalShelf() {
            cat=new LinkedList<>();
            dog=new LinkedList<>();
        }

        public void enqueue(int[] animal) {
            if(animal[1]==0){
                cat.add(animal[0]);
            }else{
                dog.add(animal[0]);
            }
        }

        public int[] dequeueAny() {
            if(dog.isEmpty()) return dequeueCat();
            if(cat.isEmpty()) return dequeueDog();
            if(cat.getFirst()<dog.getFirst()){
                return new int[]{cat.removeFirst(),0};
            }
            else{
                return new int[]{dog.removeFirst(),1};
            }
        }

        public int[] dequeueDog() {
            if(dog.isEmpty()) return new int[]{-1,-1};
            return new int[]{dog.removeFirst(),1};
        }

        public int[] dequeueCat() {
            if(cat.isEmpty()) return new int[]{-1,-1};
            return new int[]{cat.removeFirst(),0};
        }
    }
}
